Repository navigation
perf(runtime): store instance fields in the object and share one slot for monitor, hash and VM data, cutting a small object from 107 to 32 bytes - #102
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
This PR changes the Java object layout: instance fields are now stored as properties f0, f1... on the object itself instead of a separate f array; monitor, identity hash, and VM data share a single s slot. The change reduces object size significantly and enables Skynet to run in 1.5GB heap. However, cloneObject incorrectly copies the s slot (monitor/hash/VM data) to the clone via setData(copy, dataOf(o)), causing the clone to share the monitor with the original.
Not approved: the diff of src/natives/stackwalk.ts, src/natives/strings.ts, src/runtime.ts, src/snapshot.ts, test/java/ObjectLayout.java was too large to read.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict comment
…t recurse into itself
|
On |
|
Review of the files the review bot could not read ( Checked:
Minor, not bugs:
|
There was a problem hiding this comment.
This PR overhauls the Java object layout: instance fields move from a separate f array to inline properties f0, f1…; the monitor, identity hash, and VM data share a single slot s (a Monitor object holds all three once any is needed); finalizable objects keep their fields in a second st object. The interpreter, JIT, JVM, and all natives are updated to use fld.key / dataOf / setData / monitorOf / monitorFor / fieldsOf / setFields / hashOf / setHash / readField / writeField / casField / addField / swapField instead of the old f[], mon, hash, x accesses. Boot snapshot format bumps from 3 to 4. Tests pass (270/0/3, Skynet now passes under -Xmx1500m, 1052/1057 OpenJDK tests pass).
Not approved: the diff of src/natives/stackwalk.ts, src/natives/strings.ts, src/runtime.ts, src/snapshot.ts, test/java/ObjectLayout.java was too large to read.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict comment
What this changes
Every Java object was a JS object with
cls,f(a separate array of its fields),mon,hashandx: about 112 B before any field. A parked virtual thread still held 1.3 to 1.6 KB of such objects, so Skynet (1,000,000 virtual threads in-Xmx1500m) ran out of memory.s:null, the hash once taken, or aMonitorthat holds the hash and the VM data too. Compiled code gets an inline monitor fast path.f0,f1, ... of the object itself (JField.key). One constructor is generated per pattern of field kinds, so classes with the same kinds share one engine shape. The interpreter uses a named load for the first 8 slots, and Unsafe offsets go through per-slot accessors.st, which the Finalizer holds, so the object can be collected whilefinalize()still sees the fields.Tests
Bytes per object (array slot included),
nextagainst this branch:IntegerArrayListHashMapVirtualThreadwaitnext/ branch): park ping-pong 67 / 52 ms, synchronized loop 221 / 197 ms, CPU bench total 561 / 545 ms, javac 6.1 / 6.0 s (heap after GC 175 / 175 MB), cold start 0.56 / 0.52 s, start from snapshot 0.34 / 0.32 s. Interpreter only: 2,172 / 2,135 ms.-Xmx1500m, 10 iterations) now passes, 28 to 43 s per iteration, peak RSS 1.85 GB. It ran out of memory before.pnpm test: 270 pass, 0 fail, 3 skipped, also with a check that makes any read of the oldf,mon,hashandxproperties throw. New programtest/java/ObjectLayout.java(including classes of 300 and 1,200 fields) matches HotSpot.passing.txt: 1,052 pass. The two multicast tests that fail and two of the three timeouts (DatagramSocketExample,EarlyOrDelayedParsing) do the same onnextin the same environment. The third,java/net/httpclient/ResponsePublisher.java, timed out once under load after all 160 of its cases passed; it passed onnextrun alone.Noticed, not fixed
sortafterobjectsandstringsis about 17% slower because a 5 ms scavenge lands in it. Alone or after any other single benchmark it is equal, and steady-state fill and sort are equal.